{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Bitcoin_Price_Prediction.ipynb",
      "version": "0.3.2",
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "metadata": {
        "id": "CW4pBSLhpCeP",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#Description: This program predicts the price of Bitcoin for the next 30 days\n",
        "\n",
        "#Data Source: https://www.blockchain.com/charts/market-price?\n",
        "# https://towardsdatascience.com/bitcoin-price-prediction-using-lstm-9eb0938c22bd"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "fH-cpQQ-o4dx",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import numpy as np \n",
        "import pandas as pd "
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MI4ygn_Rr5eR",
        "colab_type": "code",
        "colab": {
          "resources": {
            "http://localhost:8080/nbextensions/google.colab/files.js": {
              "data": "Ly8gQ29weXJpZ2h0IDIwMTcgR29vZ2xlIExMQwovLwovLyBMaWNlbnNlZCB1bmRlciB0aGUgQXBhY2hlIExpY2Vuc2UsIFZlcnNpb24gMi4wICh0aGUgIkxpY2Vuc2UiKTsKLy8geW91IG1heSBub3QgdXNlIHRoaXMgZmlsZSBleGNlcHQgaW4gY29tcGxpYW5jZSB3aXRoIHRoZSBMaWNlbnNlLgovLyBZb3UgbWF5IG9idGFpbiBhIGNvcHkgb2YgdGhlIExpY2Vuc2UgYXQKLy8KLy8gICAgICBodHRwOi8vd3d3LmFwYWNoZS5vcmcvbGljZW5zZXMvTElDRU5TRS0yLjAKLy8KLy8gVW5sZXNzIHJlcXVpcmVkIGJ5IGFwcGxpY2FibGUgbGF3IG9yIGFncmVlZCB0byBpbiB3cml0aW5nLCBzb2Z0d2FyZQovLyBkaXN0cmlidXRlZCB1bmRlciB0aGUgT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jogJ2NvbXBsZXRlJywKICAgIH0KICB9Owp9CgpzY29wZS5nb29nbGUgPSBzY29wZS5nb29nbGUgfHwge307CnNjb3BlLmdvb2dsZS5jb2xhYiA9IHNjb3BlLmdvb2dsZS5jb2xhYiB8fCB7fTsKc2NvcGUuZ29vZ2xlLmNvbGFiLl9maWxlcyA9IHsKICBfdXBsb2FkRmlsZXMsCiAgX3VwbG9hZEZpbGVzQ29udGludWUsCn07Cn0pKHNlbGYpOwo=",
              "ok": true,
              "headers": [
                [
                  "content-type",
                  "application/javascript"
                ]
              ],
              "status": 200,
              "status_text": ""
            }
          },
          "base_uri": "https://localhost:8080/",
          "height": 40
        },
        "outputId": "1cad346b-9c70-4056-f446-888812e32698"
      },
      "source": [
        "#Load the data\n",
        "from google.colab import files # Use to load data on Google Colab\n",
        "uploaded = files.upload() # Use to load data on Google Colab\n"
      ],
      "execution_count": 103,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "\n",
              "     <input type=\"file\" id=\"files-e92890f8-5507-4723-a31b-30a55abb6ac7\" name=\"files[]\" multiple disabled />\n",
              "     <output id=\"result-e92890f8-5507-4723-a31b-30a55abb6ac7\">\n",
              "      Upload widget is only available when the cell has been executed in the\n",
              "      current browser session. Please rerun this cell to enable.\n",
              "      </output>\n",
              "      <script src=\"/nbextensions/google.colab/files.js\"></script> "
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "9-UqT78ssU-f",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 264
        },
        "outputId": "5fc4d0eb-2f6b-4aae-b42b-303d6cee0c76"
      },
      "source": [
        "#Store the data into the variable df\n",
        "df = pd.read_csv('BitcoinPrice.csv')\n",
        "df.head(7)"
      ],
      "execution_count": 50,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Date</th>\n",
              "      <th>Price</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>2018-08-25 00:00:00</td>\n",
              "      <td>6719.429231</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>2018-08-26 00:00:00</td>\n",
              "      <td>6673.274167</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>2018-08-27 00:00:00</td>\n",
              "      <td>6719.266154</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>2018-08-28 00:00:00</td>\n",
              "      <td>7000.040000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>2018-08-29 00:00:00</td>\n",
              "      <td>7054.276429</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>2018-08-30 00:00:00</td>\n",
              "      <td>6932.662500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>2018-08-31 00:00:00</td>\n",
              "      <td>6981.946154</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "                  Date        Price\n",
              "0  2018-08-25 00:00:00  6719.429231\n",
              "1  2018-08-26 00:00:00  6673.274167\n",
              "2  2018-08-27 00:00:00  6719.266154\n",
              "3  2018-08-28 00:00:00  7000.040000\n",
              "4  2018-08-29 00:00:00  7054.276429\n",
              "5  2018-08-30 00:00:00  6932.662500\n",
              "6  2018-08-31 00:00:00  6981.946154"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 50
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "uvyHYN4ZsvjH",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#Remove the Date column\n",
        "df.drop(['Date'], 1, inplace=True)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "PmUiHhGdt1xQ",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 264
        },
        "outputId": "2cdb268e-76b6-4723-e519-45d4ab1ac086"
      },
      "source": [
        "#Show the first 7 rows of the new data set\n",
        "df.head(7)"
      ],
      "execution_count": 52,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Price</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>6719.429231</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>6673.274167</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>6719.266154</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>7000.040000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>7054.276429</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>6932.662500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>6981.946154</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "         Price\n",
              "0  6719.429231\n",
              "1  6673.274167\n",
              "2  6719.266154\n",
              "3  7000.040000\n",
              "4  7054.276429\n",
              "5  6932.662500\n",
              "6  6981.946154"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 52
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "E5NjU3Utvm2X",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "#A variable for predicting 'n' days out into the future\n",
        "prediction_days = 30 #n = 30 days\n",
        "\n",
        "#Create another column (the target or dependent variable) shifted 'n' units up\n",
        "df['Prediction'] = df[['Price']].shift(-prediction_days)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "833b3sV6vvSg",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 264
        },
        "outputId": "f964be37-5115-4764-bcb7-6008ef5ec619"
      },
      "source": [
        "#Show the first 7 rows of the new data set\n",
        "df.head(7)"
      ],
      "execution_count": 54,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Price</th>\n",
              "      <th>Prediction</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>6719.429231</td>\n",
              "      <td>6639.304167</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>6673.274167</td>\n",
              "      <td>6412.459167</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>6719.266154</td>\n",
              "      <td>6468.631667</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>7000.040000</td>\n",
              "      <td>6535.476667</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>7054.276429</td>\n",
              "      <td>6677.342500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>6932.662500</td>\n",
              "      <td>6550.474167</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>6981.946154</td>\n",
              "      <td>6593.135000</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "         Price   Prediction\n",
              "0  6719.429231  6639.304167\n",
              "1  6673.274167  6412.459167\n",
              "2  6719.266154  6468.631667\n",
              "3  7000.040000  6535.476667\n",
              "4  7054.276429  6677.342500\n",
              "5  6932.662500  6550.474167\n",
              "6  6981.946154  6593.135000"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 54
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "HZKXkSaWwZGA",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 264
        },
        "outputId": "c9c39d19-6e7e-453f-fadd-f68b786a3188"
      },
      "source": [
        "#Show the last 7 rows of the new data set\n",
        "df.tail(7)"
      ],
      "execution_count": 55,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Price</th>\n",
              "      <th>Prediction</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>358</th>\n",
              "      <td>10295.117500</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>359</th>\n",
              "      <td>10605.825833</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>360</th>\n",
              "      <td>10746.507692</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>361</th>\n",
              "      <td>10169.094167</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>362</th>\n",
              "      <td>10030.746667</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>363</th>\n",
              "      <td>10255.977500</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>364</th>\n",
              "      <td>10158.540833</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            Price  Prediction\n",
              "358  10295.117500         NaN\n",
              "359  10605.825833         NaN\n",
              "360  10746.507692         NaN\n",
              "361  10169.094167         NaN\n",
              "362  10030.746667         NaN\n",
              "363  10255.977500         NaN\n",
              "364  10158.540833         NaN"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 55
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "svWzQuGwt7av",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "5783be3c-5eb0-478c-f52c-0a730b78574f"
      },
      "source": [
        "#CREATE THE INDEPENDENT DATA SET (X)\n",
        "\n",
        "# Convert the dataframe to a numpy array and drop the prediction column\n",
        "X = np.array(df.drop(['Prediction'],1))\n",
        "\n",
        "#Remove the last 'n' rows where 'n' is the prediction_days\n",
        "X= X[:len(df)-prediction_days]\n",
        "print(X)"
      ],
      "execution_count": 56,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[[ 6719.42923077]\n",
            " [ 6673.27416667]\n",
            " [ 6719.26615385]\n",
            " [ 7000.04      ]\n",
            " [ 7054.27642857]\n",
            " [ 6932.6625    ]\n",
            " [ 6981.94615385]\n",
            " [ 7100.94666667]\n",
            " [ 7247.93538462]\n",
            " [ 7260.94923077]\n",
            " [ 7326.8525    ]\n",
            " [ 7113.06923077]\n",
            " [ 6433.27166667]\n",
            " [ 6444.80416667]\n",
            " [ 6366.1075    ]\n",
            " [ 6286.42583333]\n",
            " [ 6297.87769231]\n",
            " [ 6296.32083333]\n",
            " [ 6273.1375    ]\n",
            " [ 6450.17923077]\n",
            " [ 6499.0625    ]\n",
            " [ 6518.655     ]\n",
            " [ 6480.64416667]\n",
            " [ 6400.60083333]\n",
            " [ 6296.63166667]\n",
            " [ 6335.82666667]\n",
            " [ 6418.56266667]\n",
            " [ 6669.99083333]\n",
            " [ 6709.3125    ]\n",
            " [ 6710.445     ]\n",
            " [ 6639.30416667]\n",
            " [ 6412.45916667]\n",
            " [ 6468.63166667]\n",
            " [ 6535.47666667]\n",
            " [ 6677.3425    ]\n",
            " [ 6550.47416667]\n",
            " [ 6593.135     ]\n",
            " [ 6590.96833333]\n",
            " [ 6562.64166667]\n",
            " [ 6470.4025    ]\n",
            " [ 6563.62833333]\n",
            " [ 6568.54916667]\n",
            " [ 6581.48666667]\n",
            " [ 6558.5375    ]\n",
            " [ 6618.56769231]\n",
            " [ 6621.71166667]\n",
            " [ 6563.00916667]\n",
            " [ 6248.63583333]\n",
            " [ 6260.53083333]\n",
            " [ 6260.64583333]\n",
            " [ 6299.39916667]\n",
            " [ 6452.57166667]\n",
            " [ 6596.61833333]\n",
            " [ 6596.27615385]\n",
            " [ 6568.04076923]\n",
            " [ 6487.44416667]\n",
            " [ 6488.82583333]\n",
            " [ 6531.60166667]\n",
            " [ 6498.48583333]\n",
            " [ 6481.426     ]\n",
            " [ 6508.31      ]\n",
            " [ 6478.0825    ]\n",
            " [ 6473.75333333]\n",
            " [ 6465.9175    ]\n",
            " [ 6448.22166667]\n",
            " [ 6382.66833333]\n",
            " [ 6309.45285714]\n",
            " [ 6310.28416667]\n",
            " [ 6342.28083333]\n",
            " [ 6387.67416667]\n",
            " [ 6363.79583333]\n",
            " [ 6391.87333333]\n",
            " [ 6436.965     ]\n",
            " [ 6445.35416667]\n",
            " [ 6538.79      ]\n",
            " [ 6486.25166667]\n",
            " [ 6411.28083333]\n",
            " [ 6399.03333333]\n",
            " [ 6378.26833333]\n",
            " [ 6401.93666667]\n",
            " [ 6372.06333333]\n",
            " [ 6176.155     ]\n",
            " [ 5615.18      ]\n",
            " [ 5596.1925    ]\n",
            " [ 5558.24333333]\n",
            " [ 5606.04416667]\n",
            " [ 5303.9425    ]\n",
            " [ 4671.97      ]\n",
            " [ 4533.68083333]\n",
            " [ 4548.7975    ]\n",
            " [ 4309.3375    ]\n",
            " [ 4293.84083333]\n",
            " [ 3823.51166667]\n",
            " [ 3920.53666667]\n",
            " [ 3751.66833333]\n",
            " [ 4103.45384615]\n",
            " [ 4263.78333333]\n",
            " [ 4106.87166667]\n",
            " [ 4116.7775    ]\n",
            " [ 4167.54666667]\n",
            " [ 3967.52416667]\n",
            " [ 3961.49333333]\n",
            " [ 3858.34916667]\n",
            " [ 3742.94333333]\n",
            " [ 3405.64333333]\n",
            " [ 3435.34      ]\n",
            " [ 3528.80333333]\n",
            " [ 3523.96      ]\n",
            " [ 3426.19      ]\n",
            " [ 3462.04      ]\n",
            " [ 3406.7625    ]\n",
            " [ 3278.37416667]\n",
            " [ 3225.29916667]\n",
            " [ 3271.23833333]\n",
            " [ 3392.405     ]\n",
            " [ 3567.47      ]\n",
            " [ 3808.0425    ]\n",
            " [ 3982.85083333]\n",
            " [ 4015.60916667]\n",
            " [ 3910.97333333]\n",
            " [ 4027.47833333]\n",
            " [ 4178.59083333]\n",
            " [ 3813.88      ]\n",
            " [ 3825.37916667]\n",
            " [ 3747.83916667]\n",
            " [ 3743.905     ]\n",
            " [ 3912.28583333]\n",
            " [ 3832.92166667]\n",
            " [ 3791.54583333]\n",
            " [ 3752.27166667]\n",
            " [ 3867.13833333]\n",
            " [ 3865.7975    ]\n",
            " [ 3822.62666667]\n",
            " [ 3868.4875    ]\n",
            " [ 3920.45666667]\n",
            " [ 4036.09333333]\n",
            " [ 4035.855     ]\n",
            " [ 4034.13833333]\n",
            " [ 3812.58583333]\n",
            " [ 3656.73583333]\n",
            " [ 3646.34583333]\n",
            " [ 3599.84166667]\n",
            " [ 3604.1175    ]\n",
            " [ 3656.785     ]\n",
            " [ 3621.27083333]\n",
            " [ 3619.96416667]\n",
            " [ 3632.395     ]\n",
            " [ 3690.52333333]\n",
            " [ 3620.1275    ]\n",
            " [ 3548.4275    ]\n",
            " [ 3558.92416667]\n",
            " [ 3579.89666667]\n",
            " [ 3567.29916667]\n",
            " [ 3572.735     ]\n",
            " [ 3589.26083333]\n",
            " [ 3567.76333333]\n",
            " [ 3458.06666667]\n",
            " [ 3417.1675    ]\n",
            " [ 3452.22333333]\n",
            " [ 3454.00882353]\n",
            " [ 3454.19461538]\n",
            " [ 3470.07916667]\n",
            " [ 3468.305     ]\n",
            " [ 3452.32833333]\n",
            " [ 3458.70333333]\n",
            " [ 3406.82083333]\n",
            " [ 3403.96416667]\n",
            " [ 3498.86833333]\n",
            " [ 3652.21166667]\n",
            " [ 3645.27666667]\n",
            " [ 3634.77      ]\n",
            " [ 3624.15583333]\n",
            " [ 3623.07166667]\n",
            " [ 3609.86916667]\n",
            " [ 3610.74833333]\n",
            " [ 3630.39666667]\n",
            " [ 3631.55333333]\n",
            " [ 3810.78153846]\n",
            " [ 3933.14333333]\n",
            " [ 3951.565     ]\n",
            " [ 3948.41166667]\n",
            " [ 3968.65666667]\n",
            " [ 4018.04416667]\n",
            " [ 4020.12583333]\n",
            " [ 3829.56833333]\n",
            " [ 3833.31083333]\n",
            " [ 3832.61307692]\n",
            " [ 3843.58333333]\n",
            " [ 3842.13916667]\n",
            " [ 3827.4875    ]\n",
            " [ 3827.69083333]\n",
            " [ 3749.56833333]\n",
            " [ 3793.26083333]\n",
            " [ 3863.33333333]\n",
            " [ 3888.70166667]\n",
            " [ 3905.05833333]\n",
            " [ 3919.56583333]\n",
            " [ 3922.615     ]\n",
            " [ 3896.71833333]\n",
            " [ 3880.7675    ]\n",
            " [ 3881.37923077]\n",
            " [ 3883.98928571]\n",
            " [ 3918.08666667]\n",
            " [ 4011.0925    ]\n",
            " [ 3994.34833333]\n",
            " [ 3998.4975    ]\n",
            " [ 4008.65833333]\n",
            " [ 4025.02583333]\n",
            " [ 4026.63583333]\n",
            " [ 4000.335     ]\n",
            " [ 4006.11583333]\n",
            " [ 3995.32333333]\n",
            " [ 3977.45416667]\n",
            " [ 3933.95416667]\n",
            " [ 4011.36583333]\n",
            " [ 4034.05666667]\n",
            " [ 4075.52642857]\n",
            " [ 4107.34083333]\n",
            " [ 4109.31666667]\n",
            " [ 4145.10846154]\n",
            " [ 4675.1125    ]\n",
            " [ 5018.49833333]\n",
            " [ 4970.84916667]\n",
            " [ 4980.89833333]\n",
            " [ 5042.51769231]\n",
            " [ 5126.83416667]\n",
            " [ 5214.27666667]\n",
            " [ 5197.75076923]\n",
            " [ 5251.19      ]\n",
            " [ 5111.77076923]\n",
            " [ 5031.475     ]\n",
            " [ 5076.3       ]\n",
            " [ 5077.805     ]\n",
            " [ 5114.85416667]\n",
            " [ 5109.94666667]\n",
            " [ 5214.57416667]\n",
            " [ 5263.3975    ]\n",
            " [ 5255.61416667]\n",
            " [ 5302.9575    ]\n",
            " [ 5274.14583333]\n",
            " [ 5305.275     ]\n",
            " [ 5527.80166667]\n",
            " [ 5465.515     ]\n",
            " [ 5421.52666667]\n",
            " [ 5280.61666667]\n",
            " [ 5281.80916667]\n",
            " [ 5306.695     ]\n",
            " [ 5277.88333333]\n",
            " [ 5262.36333333]\n",
            " [ 5310.17333333]\n",
            " [ 5364.99166667]\n",
            " [ 5633.7475    ]\n",
            " [ 5697.92333333]\n",
            " [ 5718.22916667]\n",
            " [ 5654.35333333]\n",
            " [ 5863.52333333]\n",
            " [ 5851.67076923]\n",
            " [ 6056.4175    ]\n",
            " [ 6302.6125    ]\n",
            " [ 6833.35083333]\n",
            " [ 7152.48416667]\n",
            " [ 7447.11416667]\n",
            " [ 8005.25083333]\n",
            " [ 8063.89583333]\n",
            " [ 7979.575     ]\n",
            " [ 7265.96333333]\n",
            " [ 7338.52083333]\n",
            " [ 7894.92666667]\n",
            " [ 7926.705     ]\n",
            " [ 7954.80833333]\n",
            " [ 7896.51083333]\n",
            " [ 7688.52583333]\n",
            " [ 7972.71916667]\n",
            " [ 8046.10769231]\n",
            " [ 8114.9325    ]\n",
            " [ 8779.97083333]\n",
            " [ 8727.90083333]\n",
            " [ 8646.195     ]\n",
            " [ 8641.89166667]\n",
            " [ 8342.77      ]\n",
            " [ 8543.03      ]\n",
            " [ 8663.6425    ]\n",
            " [ 8546.17166667]\n",
            " [ 7848.41583333]\n",
            " [ 7765.68833333]\n",
            " [ 7756.9575    ]\n",
            " [ 7920.945     ]\n",
            " [ 7941.22166667]\n",
            " [ 7817.76833333]\n",
            " [ 7815.13583333]\n",
            " [ 7914.53916667]\n",
            " [ 8033.30666667]\n",
            " [ 8163.66333333]\n",
            " [ 8342.24076923]\n",
            " [ 8721.645     ]\n",
            " [ 9096.28583333]\n",
            " [ 9227.125     ]\n",
            " [ 9160.0675    ]\n",
            " [ 9147.005     ]\n",
            " [ 9346.0725    ]\n",
            " [ 9791.0175    ]\n",
            " [10730.39166667]\n",
            " [10748.01166667]\n",
            " [10851.84833333]\n",
            " [11314.76153846]\n",
            " [12686.38833333]\n",
            " [11834.12416667]\n",
            " [11665.57583333]\n",
            " [11886.88615385]\n",
            " [11545.63333333]\n",
            " [10690.83333333]\n",
            " [10300.4875    ]\n",
            " [11342.3175    ]\n",
            " [11779.45083333]\n",
            " [11118.8875    ]\n",
            " [11411.61666667]\n",
            " [11310.50666667]\n",
            " [11788.06916667]\n",
            " [12567.70384615]\n",
            " [12668.62916667]\n",
            " [11560.6025    ]\n",
            " [11577.69538462]\n",
            " [11412.12416667]\n",
            " [10852.92666667]\n",
            " [10438.55416667]\n",
            " [10300.41166667]\n",
            " [ 9584.47583333]\n",
            " [10092.75166667]\n",
            " [10455.73      ]\n",
            " [10685.415     ]\n",
            " [10569.305     ]\n",
            " [10449.62666667]\n",
            " [10044.11333333]\n",
            " [ 9708.43583333]\n",
            " [10021.325     ]]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "gs0EGeggyVw5",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "0ac47193-8443-4d8f-9732-61fbd89a94c5"
      },
      "source": [
        "#CREATE THE DEPENDENT DATA SET (y)\n",
        "\n",
        "# Convert the dataframe to a numpy array (All of the values including the NaN's)\n",
        "y = np.array(df['Prediction'])\n",
        "\n",
        "# Get all of the y values except the last 'n' rows\n",
        "y = y[:-prediction_days]\n",
        "print(y)"
      ],
      "execution_count": 57,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[ 6639.30416667  6412.45916667  6468.63166667  6535.47666667\n",
            "  6677.3425      6550.47416667  6593.135       6590.96833333\n",
            "  6562.64166667  6470.4025      6563.62833333  6568.54916667\n",
            "  6581.48666667  6558.5375      6618.56769231  6621.71166667\n",
            "  6563.00916667  6248.63583333  6260.53083333  6260.64583333\n",
            "  6299.39916667  6452.57166667  6596.61833333  6596.27615385\n",
            "  6568.04076923  6487.44416667  6488.82583333  6531.60166667\n",
            "  6498.48583333  6481.426       6508.31        6478.0825\n",
            "  6473.75333333  6465.9175      6448.22166667  6382.66833333\n",
            "  6309.45285714  6310.28416667  6342.28083333  6387.67416667\n",
            "  6363.79583333  6391.87333333  6436.965       6445.35416667\n",
            "  6538.79        6486.25166667  6411.28083333  6399.03333333\n",
            "  6378.26833333  6401.93666667  6372.06333333  6176.155\n",
            "  5615.18        5596.1925      5558.24333333  5606.04416667\n",
            "  5303.9425      4671.97        4533.68083333  4548.7975\n",
            "  4309.3375      4293.84083333  3823.51166667  3920.53666667\n",
            "  3751.66833333  4103.45384615  4263.78333333  4106.87166667\n",
            "  4116.7775      4167.54666667  3967.52416667  3961.49333333\n",
            "  3858.34916667  3742.94333333  3405.64333333  3435.34\n",
            "  3528.80333333  3523.96        3426.19        3462.04\n",
            "  3406.7625      3278.37416667  3225.29916667  3271.23833333\n",
            "  3392.405       3567.47        3808.0425      3982.85083333\n",
            "  4015.60916667  3910.97333333  4027.47833333  4178.59083333\n",
            "  3813.88        3825.37916667  3747.83916667  3743.905\n",
            "  3912.28583333  3832.92166667  3791.54583333  3752.27166667\n",
            "  3867.13833333  3865.7975      3822.62666667  3868.4875\n",
            "  3920.45666667  4036.09333333  4035.855       4034.13833333\n",
            "  3812.58583333  3656.73583333  3646.34583333  3599.84166667\n",
            "  3604.1175      3656.785       3621.27083333  3619.96416667\n",
            "  3632.395       3690.52333333  3620.1275      3548.4275\n",
            "  3558.92416667  3579.89666667  3567.29916667  3572.735\n",
            "  3589.26083333  3567.76333333  3458.06666667  3417.1675\n",
            "  3452.22333333  3454.00882353  3454.19461538  3470.07916667\n",
            "  3468.305       3452.32833333  3458.70333333  3406.82083333\n",
            "  3403.96416667  3498.86833333  3652.21166667  3645.27666667\n",
            "  3634.77        3624.15583333  3623.07166667  3609.86916667\n",
            "  3610.74833333  3630.39666667  3631.55333333  3810.78153846\n",
            "  3933.14333333  3951.565       3948.41166667  3968.65666667\n",
            "  4018.04416667  4020.12583333  3829.56833333  3833.31083333\n",
            "  3832.61307692  3843.58333333  3842.13916667  3827.4875\n",
            "  3827.69083333  3749.56833333  3793.26083333  3863.33333333\n",
            "  3888.70166667  3905.05833333  3919.56583333  3922.615\n",
            "  3896.71833333  3880.7675      3881.37923077  3883.98928571\n",
            "  3918.08666667  4011.0925      3994.34833333  3998.4975\n",
            "  4008.65833333  4025.02583333  4026.63583333  4000.335\n",
            "  4006.11583333  3995.32333333  3977.45416667  3933.95416667\n",
            "  4011.36583333  4034.05666667  4075.52642857  4107.34083333\n",
            "  4109.31666667  4145.10846154  4675.1125      5018.49833333\n",
            "  4970.84916667  4980.89833333  5042.51769231  5126.83416667\n",
            "  5214.27666667  5197.75076923  5251.19        5111.77076923\n",
            "  5031.475       5076.3         5077.805       5114.85416667\n",
            "  5109.94666667  5214.57416667  5263.3975      5255.61416667\n",
            "  5302.9575      5274.14583333  5305.275       5527.80166667\n",
            "  5465.515       5421.52666667  5280.61666667  5281.80916667\n",
            "  5306.695       5277.88333333  5262.36333333  5310.17333333\n",
            "  5364.99166667  5633.7475      5697.92333333  5718.22916667\n",
            "  5654.35333333  5863.52333333  5851.67076923  6056.4175\n",
            "  6302.6125      6833.35083333  7152.48416667  7447.11416667\n",
            "  8005.25083333  8063.89583333  7979.575       7265.96333333\n",
            "  7338.52083333  7894.92666667  7926.705       7954.80833333\n",
            "  7896.51083333  7688.52583333  7972.71916667  8046.10769231\n",
            "  8114.9325      8779.97083333  8727.90083333  8646.195\n",
            "  8641.89166667  8342.77        8543.03        8663.6425\n",
            "  8546.17166667  7848.41583333  7765.68833333  7756.9575\n",
            "  7920.945       7941.22166667  7817.76833333  7815.13583333\n",
            "  7914.53916667  8033.30666667  8163.66333333  8342.24076923\n",
            "  8721.645       9096.28583333  9227.125       9160.0675\n",
            "  9147.005       9346.0725      9791.0175     10730.39166667\n",
            " 10748.01166667 10851.84833333 11314.76153846 12686.38833333\n",
            " 11834.12416667 11665.57583333 11886.88615385 11545.63333333\n",
            " 10690.83333333 10300.4875     11342.3175     11779.45083333\n",
            " 11118.8875     11411.61666667 11310.50666667 11788.06916667\n",
            " 12567.70384615 12668.62916667 11560.6025     11577.69538462\n",
            " 11412.12416667 10852.92666667 10438.55416667 10300.41166667\n",
            "  9584.47583333 10092.75166667 10455.73       10685.415\n",
            " 10569.305      10449.62666667 10044.11333333  9708.43583333\n",
            " 10021.325       9774.2575      9725.4025      9500.32416667\n",
            "  9533.97933333  9539.7125      9873.81166667 10088.8\n",
            " 10478.90166667 10790.63       10826.275      11713.16166667\n",
            " 11759.01916667 11703.73833333 11803.88833333 11816.9125\n",
            " 11586.1725     11377.80416667 11397.80166667 11144.38916667\n",
            " 10450.81333333  9988.9475     10230.73333333 10292.38333333\n",
            " 10295.1175     10605.82583333 10746.50769231 10169.09416667\n",
            " 10030.74666667 10255.9775     10158.54083333]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "coUZY5XezPzx",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "# Split the data into 80% training and 20% testing\n",
        "from sklearn.model_selection import train_test_split\n",
        "x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.2)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "dA6E5JVV-Xn0",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 563
        },
        "outputId": "a81df9b0-0f87-4cc3-b05c-6621e76df740"
      },
      "source": [
        "# Set prediction_days_array equal to the last 30 rows of the original data set from the price column\n",
        "prediction_days_array = np.array(df.drop(['Prediction'],1))[-prediction_days:]\n",
        "print(prediction_days_array)\n",
        "\n"
      ],
      "execution_count": 96,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[[ 9774.2575    ]\n",
            " [ 9725.4025    ]\n",
            " [ 9500.32416667]\n",
            " [ 9533.97933333]\n",
            " [ 9539.7125    ]\n",
            " [ 9873.81166667]\n",
            " [10088.8       ]\n",
            " [10478.90166667]\n",
            " [10790.63      ]\n",
            " [10826.275     ]\n",
            " [11713.16166667]\n",
            " [11759.01916667]\n",
            " [11703.73833333]\n",
            " [11803.88833333]\n",
            " [11816.9125    ]\n",
            " [11586.1725    ]\n",
            " [11377.80416667]\n",
            " [11397.80166667]\n",
            " [11144.38916667]\n",
            " [10450.81333333]\n",
            " [ 9988.9475    ]\n",
            " [10230.73333333]\n",
            " [10292.38333333]\n",
            " [10295.1175    ]\n",
            " [10605.82583333]\n",
            " [10746.50769231]\n",
            " [10169.09416667]\n",
            " [10030.74666667]\n",
            " [10255.9775    ]\n",
            " [10158.54083333]]\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "numpy.ndarray"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 96
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "0tZf2wxT8D9z",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 52
        },
        "outputId": "6d18db8a-3d07-4fe3-ed6f-b30f9fcde5ce"
      },
      "source": [
        "from sklearn.svm import SVR\n",
        "# Create and train the Support Vector Machine (Regression) using the radial basis function\n",
        "svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.00001)\n",
        "svr_rbf.fit(x_train, y_train)"
      ],
      "execution_count": 79,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "SVR(C=1000.0, cache_size=200, coef0=0.0, degree=3, epsilon=0.1, gamma=1e-05,\n",
              "    kernel='rbf', max_iter=-1, shrinking=True, tol=0.001, verbose=False)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 79
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "60MyOFc18Xz1",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "outputId": "3c5d3eff-daab-47a8-932b-e3aa4936f64d"
      },
      "source": [
        "# Testing Model: Score returns the accuracy of the prediction. \n",
        "# The best possible score is 1.0\n",
        "svr_rbf_confidence = svr_rbf.score(x_test, y_test)\n",
        "print(\"svr_rbf accuracy: \", svr_rbf_confidence)"
      ],
      "execution_count": 99,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "svr_rbf accuracy:  0.7427602807178524\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Y7OSv5XMAO-M",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 605
        },
        "outputId": "b9a806ce-fe9f-4c65-b622-841b9c8e3817"
      },
      "source": [
        "# Print the predicted value\n",
        "svm_prediction = svr_rbf.predict(x_test)\n",
        "print(svm_prediction)\n",
        "\n",
        "print()\n",
        "\n",
        "#Print the actual values\n",
        "print(y_test)"
      ],
      "execution_count": 104,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[ 7475.52091701  7565.7937874   6371.2913099   4007.46275354\n",
            "  3990.72339304  3996.70429613  5800.82400543 10365.58300965\n",
            "  5993.69571569 10080.31146435  6936.79042765  3958.41092521\n",
            "  7905.37798994  3878.6445779   9388.60930153 11416.95846172\n",
            " 10623.38386077  5556.67212205 10555.36378435  3917.4565318\n",
            "  3967.49452986 10525.15438859  7161.03319111  5643.08444743\n",
            "  6238.58326017  4001.6501031  10582.9920167   8028.16810711\n",
            "  3996.74772282  7584.78827755  3841.23638228 10536.75747326\n",
            "  5602.48739155  4041.39060711  7680.13244139  3837.14702435\n",
            "  3872.45552782  4023.66930964  8535.647841   11192.77461015\n",
            "  3862.82594886  5848.70744603  3953.15542172  5526.65730491\n",
            "  5723.42716202  5517.490656    3835.9818862   6982.14190021\n",
            " 11029.01246906  4042.42478724 10307.97137884  4000.86074933\n",
            "  9950.29204349 10159.30662724  5659.29705523  3876.86665116\n",
            "  5875.74843683  5052.90664833  6103.85193588 10402.16444841\n",
            "  4008.71058894  5579.28618325  4037.65486918  5760.70116054\n",
            "  7178.91303882 10263.74087514  4579.82380463]\n",
            "\n",
            "[ 5863.52333333  7765.68833333  3982.85083333  3813.88\n",
            "  5305.275       5274.14583333  6465.9175     10092.75166667\n",
            "  4263.78333333 10449.62666667  6568.54916667  3498.86833333\n",
            "  6562.64166667  3998.4975      8033.30666667  9539.7125\n",
            "  8163.66333333  6473.75333333 11545.63333333  3905.05833333\n",
            "  5302.9575     11577.69538462  3278.37416667  4533.68083333\n",
            "  6538.79        5527.80166667 11886.88615385  8543.03\n",
            "  3632.395       8546.17166667  3863.33333333  9725.4025\n",
            "  3435.34        5251.19        3392.405       3948.41166667\n",
            "  3933.14333333  3995.32333333  6563.62833333 10021.325\n",
            "  3623.07166667  3910.97333333  3589.26083333  6260.64583333\n",
            "  6452.57166667  3858.34916667  3832.61307692  5697.92333333\n",
            "  9160.0675      5126.83416667 11412.12416667  3567.29916667\n",
            " 10292.38333333 10230.73333333  6618.56769231  3812.58583333\n",
            "  6382.66833333  3604.1175      6309.45285714  9584.47583333\n",
            "  3572.735       4293.84083333  5031.475       4015.60916667\n",
            "  7914.53916667  9533.97933333  3599.84166667]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ic4eFH0R9_KU",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 151
        },
        "outputId": "33c6efb3-b4ac-4d52-8010-bf10933ca0e7"
      },
      "source": [
        "# Print the model predictions for the next 'n=30' days\n",
        "svm_prediction = svr_rbf.predict(prediction_days_array)\n",
        "print(svm_prediction)"
      ],
      "execution_count": 97,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[10307.03252124 10271.53152569 10173.42916952 10157.76394357\n",
            " 10156.41376563 10297.59237834  9956.05024258 10325.25877779\n",
            "  9967.21486498  9921.87854538 11046.34005016 10875.76592445\n",
            " 11077.76843636 10681.48343849 10620.39533362 11364.70844677\n",
            " 11342.90246537 11377.2749394  10574.66881963 10287.5663945\n",
            " 10134.5019906   9896.14859173  9974.99273303  9979.69891582\n",
            " 10315.9849669  10047.03802787  9880.8677999  10055.58556853\n",
            "  9921.51819023  9885.01946928]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "b2vYuC3_-wtr",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 973
        },
        "outputId": "1a7021b7-b808-41d6-cbd8-1a07227e5c52"
      },
      "source": [
        "#Print the actual price for the next 'n' days, n=prediction_days=30 \n",
        "df.tail(prediction_days)"
      ],
      "execution_count": 105,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Price</th>\n",
              "      <th>Prediction</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>335</th>\n",
              "      <td>9774.257500</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>336</th>\n",
              "      <td>9725.402500</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>337</th>\n",
              "      <td>9500.324167</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>338</th>\n",
              "      <td>9533.979333</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>339</th>\n",
              "      <td>9539.712500</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>340</th>\n",
              "      <td>9873.811667</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>341</th>\n",
              "      <td>10088.800000</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>342</th>\n",
              "      <td>10478.901667</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>343</th>\n",
              "      <td>10790.630000</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>344</th>\n",
              "      <td>10826.275000</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>345</th>\n",
              "      <td>11713.161667</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>346</th>\n",
              "      <td>11759.019167</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>347</th>\n",
              "      <td>11703.738333</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>348</th>\n",
              "      <td>11803.888333</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>349</th>\n",
              "      <td>11816.912500</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>350</th>\n",
              "      <td>11586.172500</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>351</th>\n",
              "      <td>11377.804167</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>352</th>\n",
              "      <td>11397.801667</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>353</th>\n",
              "      <td>11144.389167</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>354</th>\n",
              "      <td>10450.813333</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>355</th>\n",
              "      <td>9988.947500</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>356</th>\n",
              "      <td>10230.733333</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>357</th>\n",
              "      <td>10292.383333</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>358</th>\n",
              "      <td>10295.117500</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>359</th>\n",
              "      <td>10605.825833</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>360</th>\n",
              "      <td>10746.507692</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>361</th>\n",
              "      <td>10169.094167</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>362</th>\n",
              "      <td>10030.746667</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>363</th>\n",
              "      <td>10255.977500</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>364</th>\n",
              "      <td>10158.540833</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            Price  Prediction\n",
              "335   9774.257500         NaN\n",
              "336   9725.402500         NaN\n",
              "337   9500.324167         NaN\n",
              "338   9533.979333         NaN\n",
              "339   9539.712500         NaN\n",
              "340   9873.811667         NaN\n",
              "341  10088.800000         NaN\n",
              "342  10478.901667         NaN\n",
              "343  10790.630000         NaN\n",
              "344  10826.275000         NaN\n",
              "345  11713.161667         NaN\n",
              "346  11759.019167         NaN\n",
              "347  11703.738333         NaN\n",
              "348  11803.888333         NaN\n",
              "349  11816.912500         NaN\n",
              "350  11586.172500         NaN\n",
              "351  11377.804167         NaN\n",
              "352  11397.801667         NaN\n",
              "353  11144.389167         NaN\n",
              "354  10450.813333         NaN\n",
              "355   9988.947500         NaN\n",
              "356  10230.733333         NaN\n",
              "357  10292.383333         NaN\n",
              "358  10295.117500         NaN\n",
              "359  10605.825833         NaN\n",
              "360  10746.507692         NaN\n",
              "361  10169.094167         NaN\n",
              "362  10030.746667         NaN\n",
              "363  10255.977500         NaN\n",
              "364  10158.540833         NaN"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 105
        }
      ]
    }
  ]
}
